package com.hqyj.base.controller;

import frame.base.controller.BaseController;
import com.hqyj.base.model.InfoSupplier;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

/**
 * @ProjectName: ERP-System
 * @Package: com.hqyj.base.controller
 * @ClassName: InfoSupplierController
 * @Author: LiYi
 * @Date: 2021-09-06 22:33
 */

@Controller
@RequestMapping("/baseController")
public class InfoSupplierController extends BaseController{

        @RequestMapping("/supplier.do")
        public String queryAllByInfoUser(Model model){
            // 查询所有InfoUser的信息
            List<InfoSupplier> infoSuppliers_db = infoSupplierService.queryAllByInfoSupplier();
            // 将查询的infoUsers_db数据传给前端
            model.addAttribute("infoSuppliers_db",infoSuppliers_db);
            return "view/base/infosupplier/infoSupplierList";
        }


        @RequestMapping("/addSupplier.do")
        public String addInfoUser(Model model, InfoSupplier infoSupplier){
            infoSupplierService.addSupplier(infoSupplier);
            List<InfoSupplier> infoSuppliers_db = infoSupplierService.queryAllByInfoSupplier();
            model.addAttribute("infoSuppliers_db",infoSuppliers_db);
            return "view/base/infosupplier/infoSupplierList";
        }


        @RequestMapping("/deleteInfoSupplierById.do")
        public String deleteInfoUserById(Model model, String Id){
            int urlId = Integer.parseInt(Id);
            infoSupplierService.deleteInfoSupplierById(urlId);
            List<InfoSupplier> infoSuppliers_db = infoSupplierService.queryAllByInfoSupplier();
            model.addAttribute("infoSuppliers_db",infoSuppliers_db);
            return "view/base/infosupplier/infoSupplierList";
        }


        @RequestMapping("/updateInfoSupplierUI.do")
        public String queryInfoUserById(Model model, String Id){
            int urlId = Integer.parseInt(Id);
            InfoSupplier infoSupplier_db = infoSupplierService.queryInfoSupplierById(urlId);
            System.out.println("查看数据InfoUser_Db" + infoSupplier_db);
            model.addAttribute("infoSupplier_db",infoSupplier_db);
            return "view/base/infosupplier/updateInfoSupplier";
        }
        @RequestMapping("/updateInfoSupplierById.do")
        public String updateInfoUserById(Model model, InfoSupplier infoSupplier){
            infoSupplierService.updateInfoSupplierById(infoSupplier);
            List<InfoSupplier> infoSuppliers_db = infoSupplierService.queryAllByInfoSupplier();
            // 将查询的infoUsers_db数据传给前端
            model.addAttribute("infoSuppliers_db",infoSuppliers_db);
            return "view/base/infosupplier/infoSupplierList";
        }


        @RequestMapping("/queryFuzzyInfoSupplier.do")
        public String queryFuzzyInfoSupplier(Model model, String keyword){
            System.out.println("前端的Keyword" + keyword);
            List<InfoSupplier> infoSuppliers_db = infoSupplierService.queryFuzzyInfoSupplier(keyword);
            model.addAttribute("infoSuppliers_db",infoSuppliers_db);
            return "view/base/infosupplier/infoSupplierList";
        }
}
